import React,{Component} from 'react';
import {connect} from 'dva';
import {NavBar,Icon} from 'antd-mobile';
import  NavBarItem from '../list/component/NavBarItem'
import {Switch,Route} from 'dva/router'
import {ListBox} from './style'
import Boss from '../boss/boss'
import Genius from '../genius/genius'
import Msg from '../msg/msg'
import User from '../user/user'
class List extends Component{
    constructor(){
        super();
	}
	componentDidMount(){
		//;
		//console.log(this.props.match.params.user)
		if(this.props.match.params.user === undefined){
			this.props.dispatch({type:'user/getInfo'});
		}
		this.props.dispatch({type:'user/getAllUser'})
	}
    render(){
        //const user = this.props.user
		//console.log(this.props.location);
		//var Boss = <h3>牛人</h3>
		//var Genius = <h3>牛人</h3>
		const type = this.props.type
		const {pathname} = this.props.location;
		console.log(this.props.match)
		const navList = [
			{
				path:'/boss',
				text:'牛人',
				icon:'boss',
				title:'牛人列表',
				component:Boss,
				hide:type =='genius'
			},
			{
				path:'/genius',
				text:'boss',
				icon:'job',
				title:'BOSS列表',
				component:Genius,
				hide:type == 'boss'
			},
			{
				path:'/msg',
				text:'消息',
				icon:'msg',
				title:'消息列表',
				component:Msg
			},
			{
				path:'/me',
				text:'我',
				icon:'user',
				title:'个人中心',
				component:User
			}
		]
        return(
            <ListBox>
               <NavBar mode="dark" className='fixd-header'>{navList.find((v)=>v.path===pathname).title}</NavBar>
               <div style={{marginTop:'45px'}}>
			   		<Switch>
					{
						navList.map(v=>{
							return(
							<Route key={v.path} path={v.path} component={v.component}></Route>
						)})
					}
					</Switch>
			   </div>
               <NavBarItem data={navList} ></NavBarItem>
            </ListBox>
        )
    }
}
const mapStateProps = (state)=>{
    return{
	   user:state.user.username,
	   type:state.user.type
    }
}
export default connect(mapStateProps)(List);